package com.zyh.phoenix;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Date;

public class JDBCTest {
    public static void main(String[] args) throws Exception{
        //1 加载驱动
        Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
        //2 建立连接
        String url = "jdbc:phoenix:hadoop10:2181";
        Connection conn = DriverManager.getConnection(url);
        //3 准备sql发送工具
        PreparedStatement ps = conn.prepareStatement("select * from baizhi.t_person");
        //4 执行SQL
        ResultSet rs = ps.executeQuery();
        //5 处理结果集
        while (rs.next()){
            int id = rs.getInt("id");
            String name = rs.getString("name");
            boolean sex = rs.getBoolean("sex");
            double salary = rs.getDouble("salary");
            Date birth = rs.getDate("birth");
            System.out.println("id="+id+",name="+name+",sex="+sex+",salary="+salary+",birth="+birth);
        }
        //6 关闭连接
        rs.close();
        ps.close();
        conn.close();
    }
}
